home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / beginners / tutorial / deepend / 1 - quick example commented.bb next >
Encoding:
Text File  |  2002-04-10  |  3.1 KB  |  79 lines

  1.  
  2. ; ---------------------------------------------------------------------
  3. ; Simple example of double-buffered animation - support@blitzbasic.com
  4. ; ---------------------------------------------------------------------
  5.  
  6. ; Note that anything after a ";" is a comment, and not part of the code!
  7. ; See "quick example uncommented.bb" for the raw code.
  8.  
  9. ; ---------------------------------------------------------------------
  10. ; First, we open a display 640 pixels wide and 480 pixels high...
  11. ; ---------------------------------------------------------------------
  12.  
  13. Graphics 640, 480
  14.  
  15. ; ---------------------------------------------------------------------
  16. ; Now, we set up double-buffered animation, using the 'back buffer'
  17. ; ---------------------------------------------------------------------
  18.  
  19. ; Telling Blitz to use the 'back buffer' means that all following draw
  20. ; commands will not be drawn immediately. They'll be drawn to a 'hidden'
  21. ; display, and only shown on screen once all drawing operations are
  22. ; complete, when we call the Flip command. This avoids a flickering
  23. ; display.
  24.  
  25. SetBuffer BackBuffer ()
  26.  
  27. ; ---------------------------------------------------------------------
  28. ; Load an image in the same directory as the source code...
  29. ; ---------------------------------------------------------------------
  30.  
  31. ; Here we load an image called "rocket.bmp" and store it as a 'handle'
  32. ; called 'player'. We then use this handle in our drawing operations.
  33.  
  34. ; The MaskImage line makes the area around the rocket transparent. This
  35. ; area has an RGB value of 255, 0, 255, which is bright pink (rarely
  36. ; used for anything). The background can be any colour -- just note
  37. ; the RGB values when you create it in your paint program, and use
  38. ; those instead.
  39.  
  40. player = LoadImage ("rocket.bmp")
  41. MaskImage player, 255, 0, 255
  42.  
  43. ; ---------------------------------------------------------------------
  44. ; Main game loop
  45. ; ---------------------------------------------------------------------
  46.  
  47. ; We use a 'Repeat... Until' loop (see manual for an explanation if
  48. ; you're new to this) in our main loop. This means that everything in
  49. ; between will be repeated until, in this case, the player presses
  50. ; ESC (which has a key code of 1, seen in KeyHit here).
  51.  
  52. Repeat
  53.  
  54.     ; -----------------------------------------------------------------
  55.     ; First, we clear the display...
  56.     ; -----------------------------------------------------------------
  57.     
  58.     Cls
  59.     
  60.     ; -----------------------------------------------------------------
  61.     ; Then we draw the image...
  62.     ; -----------------------------------------------------------------
  63.     
  64.     ; Remember we're drawing to a hidden display (the back buffer), so
  65.     ; this doesn't appear until Flip is called... note that MouseX ()
  66.     ; and MouseY () simply refer to the current mouse position.
  67.     
  68.     DrawImage player, MouseX (), MouseY ()    ; Draw the image
  69.     
  70.     ; -----------------------------------------------------------------
  71.     ; Then we show the result on screen...
  72.     ; -----------------------------------------------------------------
  73.     
  74.     Flip
  75.     
  76. Until KeyHit (1)
  77.  
  78. End ; Program exits here...
  79.